<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" />
    <button>发送</button>
    <h1>消息列表</h1>
    <div class="box"></div>
    <script>
      const input = document.querySelector("input");
      const btn = document.querySelector("button");
      const box = document.querySelector(".box");

      btn.addEventListener("click", function () {
        const msg = input.value.trim();
        const newP = document.createElement("p");
        newP.innerText = msg;
        box.prepend(newP);
        newP.addEventListener("click", function () {
          newP.remove();
          
        });
      });
    </script>
  </body>
</html>
